/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package facerecognitionattendance.GUI;

import ch.randelshofer.quaqua.QuaquaLookAndFeel;
import facerecognitionattendance.additional.DBConnection;
import javax.swing.JOptionPane;

/**
 *
 * @author Ali
 */
public class AdminFrame extends javax.swing.JFrame {

    /**
     * Creates new form AdminFrame
     */
    private DBConnection connection;

    public AdminFrame() {
        initComponents();
        setSize(780, 700);
        setResizable(false);
        setLocationRelativeTo(null);
        NewStudPanel studPanel = new NewStudPanel();
        studPanel.setSize(789, 664);
        connection = new DBConnection();
        NewJPanel panel = new NewJPanel();
        while (true) {
            int result = JOptionPane.showConfirmDialog(null, panel, "Login", JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                boolean isAdmin = connection.check(panel.getLogin(), new String(panel.getPassword()));
                if (isAdmin) {
                    add(studPanel);
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, "Incorect login or password.\n Please try again", "ERROR", result);
                }
            } else {
                System.exit(0);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            javax.swing.UIManager.setLookAndFeel(new QuaquaLookAndFeel());
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        }

        DBConnection connection = new DBConnection();
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                new AdminFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
